package cn.sciento.farm.devicemanager.service.impl;

import cn.sciento.farm.devicemanager.dao.entity.ResAlarmPerson;
import cn.sciento.farm.devicemanager.dao.mapper.ResAlarmPersonMapper;
import cn.sciento.farm.devicemanager.service.AlarmPersonService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlarmPersonServiceImpl implements AlarmPersonService {

    @Autowired
    private ResAlarmPersonMapper resAlarmPersonMapper;

    @Override
    public int create(ResAlarmPerson resAlarmPerson) {
        return resAlarmPersonMapper.insert(resAlarmPerson);
    }

    @Override
    public int updateById(ResAlarmPerson resAlarmPerson) {
        return resAlarmPersonMapper.updateById(resAlarmPerson);
    }

    @Override
    public int deleteById(Long id) {
        return resAlarmPersonMapper.deleteById(id);
    }

    @Override
    public List<ResAlarmPerson> getByAreaId(int areaId) {
        QueryWrapper<ResAlarmPerson> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("area_id",areaId);
        return resAlarmPersonMapper.selectList(queryWrapper);
    }

    @Override
    public ResAlarmPerson getById(Long id) {
        return resAlarmPersonMapper.selectById(id);
    }

    @Override
    public ResAlarmPerson getByPhone(String phone) {
        QueryWrapper<ResAlarmPerson> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        return resAlarmPersonMapper.selectOne(queryWrapper);
    }
}
